<?php
#
# (c)2008 South Hill Calvary Chapel
#
include_once("./root.inc.php");
include_once("${root}/common.php");
include_once("${root}/mysql/database_info.php");
include_once("${root}/mysql/common.php");
connect_select_test("ministryPages");
if (!$_GET['name']){
	printf("Missing ministry name.");
	break;
}
$ministry = mysql_fetch_array(mysql_query("SELECT * FROM `ministryPages` WHERE `searchTag` LIKE '%".$_GET['name']."%' LIMIT 0,1"));
print_html_head($ministry['ministry'], $ministry['metaKey'], $ministry['metaDesc']);
print_java_head(NULL);
begin_body();
page_title($ministry['ministry']);
if ($ministry['picasaTag']){
	$tag = $ministry['picasaTag'];
} else {
	$tag = null;
}
if ($ministry['facebook']){
	$fb = $ministry['facebook'];
} else {
	$fb = null;
}
right_bar_open($tag, $fb);
if ($ministry['rightBarExtra']){
	printf("<div class='paragraph'>\n");
	printf("%s", $ministry['rightBarExtra']);
	printf("</div>\n");
}
if ($ministry['resourceArray']){
	$resource = explode("\n", $ministry['resourceArray']);
	for ($x=0;$x<count($resource);$x++){
		$resource[$x] = explode(",", $resource[$x]);
	}
	ministry_resource_table($resource, $ministry['resourceTitle']);
}
if ($ministry['eventTag']){
	$query="SELECT * FROM `events` WHERE ministry='".$ministry['eventTag']."' ORDER BY start ASC";
	$result=mysql_query($query) or die (mysql_error());
	$num_rows=mysql_num_rows($result);
	ministry_event_table($result, $num_rows);
}
right_bar_close();
if ($ministry['reference']){
	ministry_header(array($ministry['verse'], $ministry['reference']));
}
$body = explode("\n\n", $ministry['body']);
for ($x=0;$x<count($body);$x++){
	printf("<div class='paragraph'>\n");
	printf("\t%s\n", $body[$x]);
	printf("</div>\n");
}
if ($ministry['leaderName']){
	$leader = array ($ministry['leaderName'], $ministry['leaderPhone'], $ministry['leaderEmail']);
	ministry_footer($leader, $ministry['blessing']);
}
end_page_title();
end_body();
?>